$(function () {





    $("#sycnFavorites").click(function () {
        $.ajax({
            url: "syncFavorites",
            type: "get",
            contentType: "application/json",
            dataType:"json",
            success: function (data) {
                if(data["retType"] == "0") {
                    toastr.success("同步成功!");
                    setTimeout( "window.location.reload()",1000);//延时3秒

                } else {
                    toastr.error(data["retMsg"]);
                }
            }
        });
    });


    $("#clear_pro").click(function () {
        $.ajax({
            url: "clear_pro",
            type: "get",
            contentType: "application/json",
            dataType:"json",
            success: function (data) {
                if(data["retType"] == "0") {
                    toastr.success("清理成功!!");
                } else {
                    toastr.error(data["retMsg"]);
                }
            }
        });
    });






    //菜单列表
    $('#favoriteTableEvents').bootstrapTable({
        url: "favoriteList",
        search: false,
        pagination: true,
        showRefresh: false,
        showToggle: false,
        showColumns: false,
        pageSize:15,
        height:600,
        iconSize: 'outline',
        toolbar: '#favoriteTableEventsToolbar',
        icons: {
            refresh: 'glyphicon-repeat',
            toggle: 'glyphicon-list-alt',
            columns: 'glyphicon-list'
        },
        columns:[
            {
                field:'id',
                title:'ID',
                width:60
            },
            {
                field:'code',
                title:'收藏夹ID',
                width:80
            },
            {
                field:'title',
                title:'名稱',
                width:160
            },
            {
                field:'cname',
                title:'大类目',
                width:100
            },

            {
                field:'uptime',
                title:'同步时间',
                width:100
            },
            {
                field:'action',
                title:'操作',
                width:200,
                formatter: function(value, row, index) {
                    return [
                        '<shiro:hasPermission name="admin:ordervip:update">'+
                        '<a class="editf ml10" href="javascript:void(0)" title="修改1">'+
                        '<i class="glyphicon glyphicon-edit"></i></a></shiro:hasPermission>&nbsp;&nbsp;&nbsp;&nbsp;',
                        '<shiro:hasPermission name="admin:ordervip:add">'+
                        '<a class="deletef ml12" href="javascript:void(0)" title="同步">'+
                        '<i class="glyphicon glyphicon-refresh"></i></a></shiro:hasPermission>'
                    ].join('');
                },    //紫色为添加图标（icon），插件：font-awesome，效果图见底部。
                events: {
                    'click .deletef': function(e, value, row, index) {
                        $.ajax({
                            url: "getProductByCidForList",
                            data: row.code,
                            type: "post",
                            contentType: "application/json",
                            dataType:"json",
                            success: function (data) {
                                if(data["retType"] == "0") {
                                    toastr.success("同步成功!");
                                }
                                else {
                                    toastr.error(data["retMsg"]);
                                }
                            }
                        });
                    },
                    'click .editf': function(e, value, row, index) {

                         window.location.href="doEditor/"+row.code;
                    }
                }
            }
        ]
    });

    //
    // $.ajax({
    //     url: "getProductByCidForList",
    //     data: id,
    //     type: "post",
    //     contentType: "application/json",
    //     dataType:"json",
    //     success: function (data) {
    //         if(data["retType"] == "0") {
    //             toastr.success("同步成功!");
    //         } else {
    //             alert(data["retMsg"]);
    //         }
    //     }
    // });
});